//
//  STVisitorView.m
//  OCVVeibo
//
//  Created by leergou on 16/7/19.
//  Copyright © 2016年 WhiteHouse. All rights reserved.
//

#import "STVisitorView.h"


@interface STVisitorView ()

@property (nonatomic, strong) UIImageView *feedImageView;

@property (nonatomic, strong) UIImageView *iconImgeView;

@property (nonatomic, strong) UIImageView *maskImageView;

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic,strong) NSTimer *timer;

@property (nonatomic,strong) UIButton *loginButton;

@property (nonatomic,strong) UIButton *registerButton;

@end

@implementation STVisitorView

#pragma mark - 类入口
- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

#pragma mark - 按钮点击事件
- (void)loginButtonClick:(UIBarButtonItem *)sender{
    if (self.buttonClick) {
        self.buttonClick(sender);
    }
}

#pragma mark - setViewContent
- (void)setViewContentWithIconImgName:(NSString *)iconImgName title:(NSString *)title{
    if (iconImgName) {
        // 进入的不是首页
        self.iconImgeView.image = [UIImage imageNamed:iconImgName];
        self.titleLabel.text = title;
        self.feedImageView.hidden = YES;
    } else {
        // 进入首页,开启动画
        [self startAnimation];
    }
}

#pragma mark - startAnimation
- (void)startAnimation{
    CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    basicAnimation.duration = 10;
    basicAnimation.toValue = @(M_PI * 2);
    basicAnimation.repeatCount = MAXFLOAT;
    basicAnimation.removedOnCompletion = NO; // 默认动画停止就移除,要设置成 NO,否则,再次进入首页动画消失
    [self.feedImageView.layer addAnimation:basicAnimation forKey:nil];
}

#pragma mark - setupUI
- (void)setupUI{
    
    self.backgroundColor = RGBCOLOR(237, 237, 237);
    // 添加子控件
    [self addSubview:self.feedImageView];
    [self addSubview:self.iconImgeView];
    [self addSubview:self.maskImageView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.loginButton];
    [self addSubview:self.registerButton];
}

#pragma mark - setLayout
- (void)layoutSubviews{
    [super layoutSubviews];
    // 添加约束
    [self.feedImageView makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
    }];
    
    [self.iconImgeView makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
    }];
    
    [self.maskImageView makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
    }];
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.maskImageView.bottom).offset(16);
        make.centerX.equalTo(self);
        make.width.equalTo(230);
        make.height.equalTo(36);
    }];
    
    [self.loginButton makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.bottom).offset(16);
        make.leading.equalTo(self.titleLabel.leading);
        make.size.equalTo(CGSizeMake(100, 36));
    }];
    
    [self.registerButton makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.loginButton);
        make.trailing.equalTo(self.titleLabel);
        make.size.equalTo(CGSizeMake(100, 36));
    }];
}

#pragma mark - lazy
- (UIImageView *)feedImageView{
    if (!_feedImageView) {
        _feedImageView = [[UIImageView  alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
    }
    return _feedImageView;
}

- (UIImageView *)iconImgeView{
    if (!_iconImgeView) {
        _iconImgeView = [[UIImageView  alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_house"]];
    }
    return _iconImgeView;
}

- (UIImageView *)maskImageView{
    if (!_maskImageView) {
        _maskImageView =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"]];
    }
    return _maskImageView;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.numberOfLines = 0;
        _titleLabel.font = [UIFont systemFontOfSize:14];
        _titleLabel.text = @"关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜";
    }
    return _titleLabel;
}

- (UIButton *)loginButton{
    if (!_loginButton) {
        
        _loginButton = [[UIButton alloc] initWithTitle:@"登录" bgNorImg:@"common_button_white_disable" target:self action:@selector(loginButtonClick:)];
        
        [_loginButton setTitleColor:ThemeColor forState:UIControlStateNormal];
    }
    return _loginButton;
}

- (UIButton *)registerButton{
    if (!_registerButton) {
        _registerButton = [[UIButton alloc] initWithTitle:@"注册" bgNorImg:@"common_button_white_disable" target:self action:@selector(loginButtonClick:)];
        [_registerButton setTitleColor:ThemeColor forState:UIControlStateNormal];
    }
    return _registerButton;
}




@end
